package jdbc;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class TestFristDemo {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:mysql://localhost:3306/java76?useSSL=false";
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            con = DriverManager.getConnection(url, "root", "root1234");
            //System.out.println(con.getClass().getName());
            st = con.createStatement();
            rs = st.executeQuery("select * from s_subject order by id desc");
            while (rs.next()) {
                long id = rs.getLong("id");
                String name = rs.getString("subjectname");
                int clashour = rs.getInt("classhour");
                long gradeid = rs.getLong("gradeid");
                System.out.println(id + "," + name + "," + clashour + "," + gradeid);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
